﻿using System.Xml.Serialization;
using System.IO;
using System;

namespace OpenGameEngine.Helper.Serializers
{
    public static class XmlFile
    {
        public static void Serialize<T>(Object objToSerialize, String filePath)
        {
            FileStream fs = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.Write);
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
            xmlSerializer.Serialize(fs, objToSerialize);
            fs.Close();
        }

        public static T Deserialize<T>(String filePath)
        {
            FileStream fs = File.Open(filePath, FileMode.Open, FileAccess.Read);
            XmlSerializer xmlDeserializer = new XmlSerializer(typeof(T));
            T o = (T)xmlDeserializer.Deserialize(fs);
            fs.Close();
            return o;
        }
    }
}
